package com.vader.NIO;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author kaivader
 */
public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {
        String str ="niobuffer";
        FileOutputStream fileOutputStream = new FileOutputStream("test.txt");
        FileChannel fileChannel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();

        fileChannel.write(byteBuffer);
        fileChannel.close();
    }
}
